package com.tender.controller.templates;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.net.InetAddress;

// 此处不能使用 @RestController
// @RestController
@Controller
public class HomeController {

    @Autowired
    private Environment env;

    @GetMapping("/home")
    public String home(Model model) throws Exception {
        // 业务逻辑
        model.addAttribute("username", "lucy");

        model.addAttribute("port", env.getProperty("server.port"));
        model.addAttribute("ip", InetAddress.getLocalHost().getHostAddress());

        return "index";
    }

}
